﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;

namespace CS_BEGINNER_TO_PROFICIENT.STD.ReflectionSTD
{
    public class Source
    { 
        public string Name { get; set; }
        public int Age { get; set; }
    }

    public class Destination
    {
        public string Name { get; set; }
        public int Age { get; set; }
    }

    public class ReflectionSTDP6
    {
        public static void Execute()
        {
            var source = new Source { Name = "Alice", Age = 25 };
            var destination = new Destination();

            var sourceType = typeof(Source);
            var destType = typeof(Destination);

            foreach (var prop in sourceType.GetProperties(BindingFlags.Public | BindingFlags.Instance))
            {
                var destProp = destType.GetProperty(prop.Name);
                if (destProp != null && destProp.CanWrite)
                {
                    var value = prop.GetValue(source);
                    destProp.SetValue(destination, value);
                }
            }

            Console.WriteLine($"Name: {destination.Name}, Age: {destination.Age}");
        }
    }
}
